/**
 * 
 */
package com.feib.stms.action;

import java.util.List;

import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.DontBind;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.integration.spring.SpringBean;

import com.feib.stms.model.BusinessDay;
import com.feib.stms.model.CalendarDTO;
import com.feib.stms.service.BusinessDayService;

/**
 * @title (#)Stms9013ActionBean.java<br>
 * @description 營業日維護 <br>
 * @author Lion Gao<br>
 * @version 1.0.0 2012/06/15
 * @2012/06/15 create by Lion Gao<br>
 * 
 */
public class Stms9013ActionBean extends BaseActionBean {
	
	private static final long serialVersionUID = 8222509856160478869L;
	private static final String DEFAULT_JSP = "/WEB-INF/views/stms9013/stms9013.jsp";

	/**
	 * 年
	 */
	private String qrySYear;

	/**
	 * 月
	 */
	private String qrySMon;
	
	/**
	 * 綁定行事歷DTO
	 */
	private CalendarDTO cal;
	
	/**
	 * message
	 */
	private String message;
	
	/**
	 * 綁定checkbox
	 */
	private List<BusinessDay> checkBusinessDay;
	
	@SpringBean("businessDayService")
    private BusinessDayService businessDayService;
	
	@DontBind
	@DefaultHandler
	public Resolution doDefault() {
		logger.debug("Enter doDefault method.");
		return new ForwardResolution(DEFAULT_JSP);
	}

	/**
	 * 查詢
	 * 
	 * @return
	 */
	public Resolution doQuery() {
		logger.debug("Enter doQuery mehtod.");
		//從db中撈取
		List<BusinessDay> businessDayLists = this.businessDayService.getBusinessDayByDate(qrySYear, qrySMon);
		this.cal = new CalendarDTO(Integer.parseInt(qrySYear), Integer.parseInt(qrySMon) - 1 ,businessDayLists);
		return new ForwardResolution(DEFAULT_JSP);
	}
	
	 /**
     * 確認
     * @return
     */
    public Resolution doSave()
    {	
    	logger.debug("Enter doSave mehtod.");
    	try{
    		int result = businessDayService.insertBusinessDay(qrySYear, qrySMon, checkBusinessDay);
    		if(result > 0){
    			message = "營業日維護成功!!";
    		}else{
    			message = "營業日維護失敗!!";
    		}
    		return new ForwardResolution(DEFAULT_JSP); 	
    	}catch(Exception e){
    		logger.error("營業日維護(Stms9013ActionBean.doSave):", e);
    		return new ForwardResolution(DEFAULT_JSP); 
    	}
    }
    
	/**
	 * @return cal
	 */
	public CalendarDTO getCal() {
		return cal;
	}

	/**
	 * @param cal 的設定的 cal
	 */
	public void setCal(CalendarDTO cal) {
		this.cal = cal;
	}

	/**
	 * @return message
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * @param message 的設定的 message
	 */
	public void setMessage(String message) {
		this.message = message;
	}

	/**
	 * @return qrySMon
	 */
	public String getQrySMon() {
		return qrySMon;
	}

	/**
	 * @param qrySMon 的設定的 qrySMon
	 */
	public void setQrySMon(String qrySMon) {
		this.qrySMon = qrySMon;
	}

	/**
	 * @return qrySYear
	 */
	public String getQrySYear() {
		return qrySYear;
	}

	/**
	 * @param qrySYear 的設定的 qrySYear
	 */
	public void setQrySYear(String qrySYear) {
		this.qrySYear = qrySYear;
	}

	/**
	 * @return checkBusinessDay
	 */
	public List<BusinessDay> getCheckBusinessDay() {
		return checkBusinessDay;
	}

	/**
	 * @param checkBusinessDay 的設定的 checkBusinessDay
	 */
	public void setCheckBusinessDay(List<BusinessDay> checkBusinessDay) {
		this.checkBusinessDay = checkBusinessDay;
	}
	
	

}
